10. Classes and Objects
10 Classes And Objects
1- Copy this code to your editor and save it on your VM Desktop as Robotic.cpp:
#include <iostream>
using namespace std;
class Robot
{
public:
int Speed()
{
return 10;
}
};
int main()
{
Robot robot1;
cout << "Speed= " << robot1.Speed() << endl;
return 0;
}
2- Next, Navigate to Desktop:
$ cd Desktop
3- It’s time to compile the code:
$ g++ Robotic.cpp -o app
4- Now, run your program:
$ ./app
5- After running the executable file, check the robot speed displayed in your terminal:
Class and Object Syntax
SOLUTION:
Fruit apple;Access Modifiers